package com.spring.student.systemDB;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanProPertyBowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.Component;
import org.springframework.stereotype.Component;

@Component("userManage")

public class UserManageImpl implements UserManage {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Override
    public boolean login(User user) {
        String sql = "select * from users where number = ? and password = ?and identity=?";
        Object[] obj = new Object[]{
                user.getNumber(),
                user.getPassword(),
                user.getIdentity()
        };
        RowMapper<User>rowMapper;
        rowMapper = new BeanPropertyRowMapper<User>(User.class);
        List<User>user_db = jdbcTemplate.query(sql,rowMapper,obj);
        if(!user_db.isEmpty()){
            return true;
        }
        return false;
    }
    @Override
    public void quit() {
        System.out.println("退出登录");
    }
}
